home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Freeware / reportplus / source / f12.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  15.8 KB  |  514 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/gadgetclass.h>
  5. #include <workbench/icon.h>
  6. #include <workbench/workbench.h>
  7. #include <dos/dosextens.h>
  8.  
  9. #include "rp.h" // before icon protos
  10.  
  11. #include <clib/alib_protos.h>
  12. #include <clib/exec_protos.h>
  13. #include <clib/intuition_protos.h>
  14. #include <clib/icon_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <pragmas/icon_pragmas.h>
  17. #include <reaction/reaction.h>
  18. #include <gadgets/chooser.h>
  19. #include <pragmas/chooser_pragmas.h>
  20. #include <gadgets/string.h>
  21. #include <pragmas/string_pragmas.h>
  22. #include <gadgets/checkbox.h>
  23. #include <pragmas/checkbox_pragmas.h>
  24. #include <gadgets/layout.h>
  25. #include <pragmas/layout_pragmas.h>
  26. #include <gadgets/button.h>
  27. #include <pragmas/button_pragmas.h>
  28. #include <images/label.h>
  29. #include <pragmas/label_pragmas.h>
  30. #include <proto/label.h>
  31. #include <classes/window.h>
  32. #include <pragmas/window_pragmas.h>
  33.  
  34. #include <stdlib.h>
  35. #include <string.h>
  36.  
  37. AGLOBAL ABOOL              quit              = FALSE;
  38. AGLOBAL struct Gadget*     icon_gadgets[GIDS_12 + 1];
  39. AGLOBAL struct IconStruct  icon =
  40. {   TRUE, FALSE,
  41.     WBDRAWER
  42. };
  43.  
  44. // from rp.c
  45. IMPORT Object*             WinObject[FUNCTIONS + 1];
  46. IMPORT TEXT                IOBuffer[LONGESTFIELD + 1];
  47. IMPORT SBYTE               page;
  48. IMPORT TEXT                asldir[VLONGFIELD + 1];
  49. IMPORT ULONG               signal;
  50. IMPORT struct Window*      MainWindowPtr;
  51. IMPORT struct Screen*      ScreenPtr;
  52. IMPORT struct SharedStruct shared;
  53. IMPORT struct Library     *ButtonBase,
  54.                           *CheckBoxBase,
  55.                           *ChooserBase,
  56.                           *IconBase,
  57.                           *LabelBase,
  58.                           *LayoutBase,
  59.                           *StringBase,
  60.                           *WindowBase;
  61. IMPORT struct Menu*        MenuPtr;
  62. IMPORT ABOOL               done;
  63. IMPORT TEXT                aslresult[VLONGFIELD + 1];
  64.  
  65. MODULE ABOOL               stop;
  66. MODULE STRPTR IconOptions[8] =
  67. {   "Disk",
  68.     "Drawer",
  69.     "Tool",
  70.     "Project",
  71.     "Trashcan",
  72.     "Device",
  73.     "Kickstart",
  74.     "AppIcon"
  75. };
  76. /* icon.type is the same as the values used by the system. So, the
  77. value used by the gadget is one less than the actual value. */
  78.  
  79. AGLOBAL void icon1(void)
  80. {   ULONG               i;
  81.     struct List         ChooserList;
  82.     struct ChooserNode *ChooserNodePtr[7 + 1];
  83.     struct Hook         Hook12Struct;
  84.  
  85.     shared.pathname[0] = 0;
  86.  
  87.     NewList(&ChooserList);
  88.     for (i = 0; i <= 7; i++)
  89.     {   if (!(ChooserNodePtr[i] = (struct ChooserNode *) AllocChooserNode(CNA_Text, IconOptions[i], TAG_DONE)))
  90.         {   rq("Can't allocate chooser node!");
  91.         }
  92.         AddTail(&ChooserList, (struct Node *) ChooserNodePtr[i]);
  93.     } // automatically freed by ReAction at DisposeObject() time
  94.  
  95.     /* Create the window object. */
  96.     lockscreen();
  97.     gadtools();
  98.     InitHook(&Hook12Struct, Hook12Func, NULL);
  99.  
  100.     if (!(WinObject[12] =         NewObject(WINDOW_GetClass(), NULL,
  101.     // window
  102.     WA_PubScreen,                 ScreenPtr,
  103.     WA_ScreenTitle,               "Report+",
  104.     WA_Title,                     "Report+: Icon Processor",
  105.     WA_Activate,                  TRUE,
  106.     WA_DepthGadget,               TRUE,
  107.     WA_DragBar,                   TRUE,
  108.     WA_CloseGadget,               TRUE,
  109.     WA_SizeGadget,                TRUE,
  110.     WA_IDCMP,                     IDCMP_RAWKEY,
  111.     WINDOW_IDCMPHook,             &Hook12Struct,
  112.     WINDOW_IDCMPHookBits,         IDCMP_RAWKEY,
  113.     WINDOW_MenuStrip,             MenuPtr,
  114.     WINDOW_Position,              WPOS_CENTERSCREEN,
  115.     WINDOW_ParentGroup,           icon_gadgets[GID_12_LY1] =
  116.                                   NewObject(LAYOUT_GetClass(), NULL,
  117.             // root-layout
  118.             LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
  119.             LAYOUT_SpaceOuter,        TRUE,
  120.             LAYOUT_DeferLayout,       TRUE,
  121.             LAYOUT_AddChild,          icon_gadgets[GID_12_CH1] =
  122.                                       NewObject(CHOOSER_GetClass(), NULL,
  123.                 // chooser
  124.                 GA_ID,                GID_12_CH1,
  125.                 GA_RelVerify,         TRUE,
  126.                 CHOOSER_PopUp,        TRUE,
  127.                 CHOOSER_Labels,       &ChooserList,
  128.                 CHOOSER_Selected,     (WORD) (icon.type - 1),
  129.                 TAG_END),
  130.             CHILD_WeightedHeight,     0,
  131.             LAYOUT_AddChild,          icon_gadgets[GID_12_CB1] =
  132.                                       NewObject(CHECKBOX_GetClass(), NULL,
  133.                 // checkbox
  134.                 GA_ID,                GID_12_CB1,
  135.                 GA_RelVerify,         TRUE,
  136.                 GA_Text,              "_Optimize colours?",
  137.                 GA_Selected,          (BOOL) icon.optimize,
  138.                 TAG_END),
  139.             CHILD_WeightedHeight,     0,
  140.             LAYOUT_AddChild,          icon_gadgets[GID_12_CB2] =
  141.                                       NewObject(CHECKBOX_GetClass(), NULL,
  142.                 // checkbox
  143.                 GA_ID,                GID_12_CB2,
  144.                 GA_RelVerify,         TRUE,
  145.                 GA_Text,              "Preserve p_lanar data?",
  146.                 GA_Selected,          (BOOL) icon.planar,
  147.                 TAG_END),
  148.             CHILD_WeightedHeight,     0,
  149.             LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  150.                 // layout
  151.                 LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  152.                 LAYOUT_SpaceOuter,    TRUE,
  153.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  154.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  155.                 LAYOUT_BevelStyle,    BVS_FIELD,
  156.                 LAYOUT_AddImage,      NewObject(LABEL_GetClass(), NULL,
  157.                     // label
  158.                     LABEL_Text,       "_Pathname(s):",
  159.                     LABEL_Justification,LJ_LEFT,
  160.                     TAG_END),
  161.                 LAYOUT_AddChild,      icon_gadgets[GID_12_ST1] =
  162.                                       NewObject(STRING_GetClass(), NULL,
  163.                     // string        
  164.                     GA_ID,            GID_12_ST1,
  165.                     GA_RelVerify,     TRUE,
  166.                     STRINGA_TextVal,  shared.pathname,
  167.                     STRINGA_MinVisible,35,
  168.                     TAG_END),
  169.                 LAYOUT_AddChild,      icon_gadgets[GID_12_BU1] =
  170.                                       NewObject(NULL, "button.gadget",
  171.                     // button
  172.                     GA_ID,            GID_12_BU1,
  173.                     GA_RelVerify,     TRUE,
  174.                     BUTTON_AutoButton,BAG_POPFILE,
  175.                     TAG_END),
  176.                 CHILD_WeightedWidth,  0,
  177.                 TAG_END),
  178.             CHILD_WeightedHeight,     0,
  179.             LAYOUT_AddChild,          icon_gadgets[GID_12_ST2] =
  180.                                       NewObject(STRING_GetClass(), NULL,
  181.                 // string        
  182.                 GA_ReadOnly,          TRUE,
  183.                 GA_ID,                GID_12_ST2,
  184.                 STRINGA_TextVal,      "Ready.",
  185.                 TAG_END),
  186.             CHILD_WeightedHeight,     0,
  187.             LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  188.                 // layout
  189.                 LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  190.                 LAYOUT_SpaceOuter,    TRUE,
  191.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  192.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  193.                 LAYOUT_BevelStyle,    BVS_FIELD,
  194.                 LAYOUT_AddChild,      icon_gadgets[GID_12_BU3] =
  195.                                       NewObject(NULL, "button.gadget",
  196.                     // button
  197.                     GA_ID,            GID_12_BU3,
  198.                     GA_RelVerify,     TRUE,
  199.                     GA_Text,          "Pro_cess",
  200.                 TAG_END),
  201.                 CHILD_WeightedWidth,  50,
  202.                 LAYOUT_AddChild,      icon_gadgets[GID_12_BU4] =
  203.                                       NewObject(NULL, "button.gadget",
  204.                     // button
  205.                     GA_ID,            GID_12_BU2,
  206.                     GA_RelVerify,     TRUE,
  207.                     GA_Text,          "Stop",
  208.                     GA_Disabled,      TRUE,
  209.                     TAG_END),
  210.                 CHILD_WeightedWidth,  50,
  211.                 TAG_END),
  212.             CHILD_WeightedHeight,     0,
  213.             LAYOUT_AddChild,          icon_gadgets[GID_12_BU2] =
  214.                                       NewObject(NULL, "button.gadget",
  215.                 // button
  216.                 GA_ID,                GID_12_BU2,
  217.                 GA_RelVerify,         TRUE,
  218.                 GA_Text,              "Menu",
  219.                 TAG_END),
  220.             CHILD_WeightedHeight,     0,
  221.             TAG_END),
  222.     TAG_END)
  223.     ))
  224.     {   rq("Can't create ReAction objects!");
  225.     }
  226.     unlockscreen();
  227.     openwindow();
  228.     ActivateLayoutGadget(icon_gadgets[GID_12_LY1], MainWindowPtr, NULL, (Object) icon_gadgets[GID_12_ST1]);
  229.     loop();
  230.     closewindow();
  231.     if (quit)
  232.     {   cleanexit(EXIT_SUCCESS);
  233. }   }
  234.  
  235. AGLOBAL void icon_do(void)
  236. {   STRPTR stringptr;
  237.  
  238.     if (!(GetAttr
  239.     (   CHOOSER_Selected, icon_gadgets[GID_12_CH1], (ULONG *) &(icon.type)
  240.     )))
  241.     {   rq("Unsupported inquiry!"); // should never happen
  242.     }
  243.     icon.type++;
  244.  
  245.     if (!(GetAttr
  246.     (   STRINGA_TextVal, icon_gadgets[GID_12_ST1], (ULONG *) &stringptr
  247.     )))
  248.     {   rq("Unsupported inquiry!"); // should never happen
  249.     }
  250.     strcpy(shared.pathname, stringptr);
  251.  
  252.     if (!(GetAttr
  253.     (   GA_Selected, icon_gadgets[GID_12_CB1], (ULONG *) &(icon.optimize)
  254.     )))
  255.     {   rq("Unsupported inquiry!"); // should never happen
  256.     }
  257.     if (!(GetAttr
  258.     (   GA_Selected, icon_gadgets[GID_12_CB2], (ULONG *) &(icon.planar)
  259.     )))
  260.     {   rq("Unsupported inquiry!"); // should never happen
  261.     }
  262.  
  263.     SetGadgetAttrs
  264.     (   icon_gadgets[GID_12_CH1], MainWindowPtr, NULL,
  265.         GA_Disabled, TRUE,
  266.         TAG_END
  267.     );
  268.     SetGadgetAttrs
  269.     (   icon_gadgets[GID_12_CB1], MainWindowPtr, NULL,
  270.         GA_Disabled, TRUE,
  271.         TAG_END
  272.     );
  273.     SetGadgetAttrs
  274.     (   icon_gadgets[GID_12_CB2], MainWindowPtr, NULL,
  275.         GA_Disabled, TRUE,
  276.         TAG_END
  277.     );
  278.     SetGadgetAttrs
  279.     (   icon_gadgets[GID_12_ST1], MainWindowPtr, NULL,
  280.         GA_Disabled, TRUE,
  281.         TAG_END
  282.     );
  283.     SetGadgetAttrs
  284.     (   icon_gadgets[GID_12_BU1], MainWindowPtr, NULL,
  285.         GA_Disabled, TRUE,
  286.         TAG_END
  287.     );
  288.     SetGadgetAttrs
  289.     (   icon_gadgets[GID_12_BU2], MainWindowPtr, NULL,
  290.         GA_Disabled, TRUE,
  291.         TAG_END
  292.     );
  293.     SetGadgetAttrs
  294.     (   icon_gadgets[GID_12_BU3], MainWindowPtr, NULL,
  295.         GA_Disabled, TRUE,
  296.         TAG_END
  297.     );
  298.     SetGadgetAttrs
  299.     (   icon_gadgets[GID_12_BU4], MainWindowPtr, NULL,
  300.         GA_Disabled, FALSE,
  301.         TAG_END
  302.     );
  303.     SetAttrs
  304.     (   WinObject[12],
  305.         WA_BusyPointer, TRUE,
  306.         TAG_END
  307.     );
  308.                           
  309.     convert(TRUE);
  310.  
  311.     if (!stop)
  312.     {   SetGadgetAttrs
  313.         (   icon_gadgets[GID_12_ST2], MainWindowPtr, NULL,
  314.             STRINGA_TextVal, "All done.",
  315.             TAG_END
  316.         );
  317.     }
  318.     SetAttrs
  319.     (   WinObject[12],
  320.         WA_BusyPointer, FALSE,
  321.         TAG_END
  322.     );
  323.     SetGadgetAttrs
  324.     (   icon_gadgets[GID_12_CH1], MainWindowPtr, NULL,
  325.         GA_Disabled, FALSE,
  326.         TAG_END
  327.     );
  328.     SetGadgetAttrs
  329.     (   icon_gadgets[GID_12_CB1], MainWindowPtr, NULL,
  330.         GA_Disabled, FALSE,
  331.         TAG_END
  332.     );
  333.     SetGadgetAttrs
  334.     (   icon_gadgets[GID_12_CB2], MainWindowPtr, NULL,
  335.         GA_Disabled, FALSE,
  336.         TAG_END
  337.     );
  338.     SetGadgetAttrs
  339.     (   icon_gadgets[GID_12_ST1], MainWindowPtr, NULL,
  340.         GA_Disabled, FALSE,
  341.         TAG_END
  342.     );
  343.     SetGadgetAttrs
  344.     (   icon_gadgets[GID_12_BU1], MainWindowPtr, NULL,
  345.         GA_Disabled, FALSE,
  346.         TAG_END
  347.     );
  348.     SetGadgetAttrs
  349.     (   icon_gadgets[GID_12_BU2], MainWindowPtr, NULL,
  350.         GA_Disabled, FALSE,
  351.         TAG_END
  352.     );
  353.     SetGadgetAttrs
  354.     (   icon_gadgets[GID_12_BU3], MainWindowPtr, NULL,
  355.         GA_Disabled, FALSE,
  356.         TAG_END
  357.     );
  358.     SetGadgetAttrs
  359.     (   icon_gadgets[GID_12_BU4], MainWindowPtr, NULL,
  360.         GA_Disabled, TRUE,
  361.         TAG_END
  362.     );
  363. }
  364.  
  365. AGLOBAL void iconconvert(ABOOL gui)
  366. {   TEXT               saystring[LONGFIELD + 1];
  367.     ULONG              length = strlen(shared.thisfile);
  368.     struct DiskObject* IconPtr;
  369.  
  370.     if (length <= 5) // in case we get passed an empty string
  371.     {   return;
  372.     }
  373.     if (!stricmp(&(shared.thisfile[length - 5]), ".info"))
  374.     {   shared.thisfile[length - 5] = 0;
  375.     }
  376.    
  377.     strcpy(saystring, "Processing ");
  378.     strcat(saystring, shared.thisfile);
  379.     strcat(saystring, ".info...");
  380.     if (gui)
  381.     {   SetGadgetAttrs
  382.         (   icon_gadgets[GID_12_ST2], MainWindowPtr, NULL,
  383.             STRINGA_TextVal, saystring,
  384.             TAG_END
  385.         );
  386.     } else
  387.     {   Printf("%s", saystring);
  388.         Flush(Output());
  389.         saystring[0] = 0;
  390.     }
  391.  
  392.     if (IconPtr = GetIconTags(shared.thisfile, TAG_DONE))
  393.     {   IconPtr->do_Type = (UWORD) icon.type;
  394.         if (PutIconTags(shared.thisfile, IconPtr,
  395.             ICONPUTA_NotifyWorkbench,     TRUE,
  396.             ICONPUTA_DropPlanarIconImage, (BOOL) !icon.planar,
  397.             ICONPUTA_OptimizeImageSpace,  (BOOL) icon.optimize,
  398.             TAG_DONE
  399.         ))
  400.         {   strcat(saystring, "done.");
  401.         } else strcat(saystring, "failed to write!");
  402.         FreeDiskObject(IconPtr);
  403.     } else strcat(saystring, "failed to read!");
  404.  
  405.     if (gui)
  406.     {   SetGadgetAttrs
  407.         (   icon_gadgets[GID_12_ST2], MainWindowPtr, NULL,
  408.             STRINGA_TextVal, saystring,
  409.             TAG_END
  410.         );
  411.     } else
  412.     {   Printf("%s\n", saystring);
  413.     }
  414.  
  415.     checkabort(gui);
  416. }
  417.  
  418. AGLOBAL void icon_loop(ULONG gid)
  419. {   STRPTR stringptr;
  420.  
  421.     switch (gid)
  422.     {
  423.     case GID_12_CH1:
  424.         if (!(GetAttr
  425.         (   CHOOSER_Selected, icon_gadgets[GID_12_CH1], (ULONG *) &(icon.type)
  426.         )))
  427.         {   rq("Unsupported inquiry!"); // should never happen
  428.         }
  429.         icon.type++;
  430.     break;
  431.     case GID_12_ST1:
  432.         if (!(GetAttr
  433.         (   STRINGA_TextVal, icon_gadgets[GID_12_ST1], (ULONG *) &stringptr
  434.         )))
  435.         {   rq("Unsupported inquiry!"); // should never happen
  436.         }
  437.         strcpy(shared.pathname, stringptr);
  438.     break;
  439.     case GID_12_BU1:
  440.         multiasl("#?.info");
  441.         SetGadgetAttrs
  442.         (   icon_gadgets[GID_12_ST1], MainWindowPtr, NULL,
  443.             STRINGA_TextVal, shared.pathname,
  444.             TAG_END
  445.         );
  446.     break;
  447.     case GID_12_BU2:
  448.         page = 0;
  449.     break;
  450.     case GID_12_BU3:
  451.         icon_do();
  452.     break;
  453.     case GID_12_CB1:
  454.         if (!(GetAttr
  455.         (   GA_Selected, icon_gadgets[GID_12_CB1], (ULONG *) &(icon.optimize)
  456.         )))
  457.         {   rq("Unsupported inquiry!"); // should never happen
  458.         }
  459.     break;
  460.     case GID_12_CB2:
  461.         if (!(GetAttr
  462.         (   GA_Selected, icon_gadgets[GID_12_CB2], (ULONG *) &(icon.planar)
  463.         )))
  464.         {   rq("Unsupported inquiry!"); // should never happen
  465.         }
  466.     break;
  467.     default:
  468.     break;
  469. }   }
  470.  
  471. AGLOBAL ULONG Hook12Func(struct Hook *h, VOID *o, VOID *msg)
  472. {   /* "When the hook is called, the data argument points to the 
  473.     window object and message argument to the IntuiMessage." */
  474.  
  475.     UWORD code, qual;
  476.  
  477.     geta4(); // wait till here before doing anything
  478.  
  479.     code = ((struct IntuiMessage *) msg)->Code;
  480.     qual = ((struct IntuiMessage *) msg)->Qualifier;
  481.  
  482.     switch(code)
  483.     {
  484.     case SCAN_HELP:
  485.         helpabout();
  486.     break;
  487.     case SCAN_ESCAPE:
  488.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  489.         {   cleanexit(EXIT_SUCCESS);
  490.         } else page = 0;
  491.     break;
  492.     case SCAN_P:
  493.         ActivateLayoutGadget(icon_gadgets[GID_12_LY1], MainWindowPtr, NULL, (Object) icon_gadgets[GID_12_ST1]);
  494.     break;
  495.     default:
  496.     break;
  497.     }
  498.  
  499.     return(1);
  500. }
  501.  
  502. AGLOBAL void icon_die(void)
  503. {   IOBuffer[16] = (UBYTE) icon.type;
  504.     IOBuffer[17] = (UBYTE) icon.optimize;
  505.     IOBuffer[18] = (UBYTE) icon.planar;
  506. }
  507.  
  508. AGLOBAL void icon_config(void)
  509. {   icon.type     = IOBuffer[16];
  510.     icon.optimize = IOBuffer[17];
  511.     icon.planar   = IOBuffer[18];
  512. }
  513.  
  514.